import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/components/product/set_meal.dart';
import 'package:meal/components/product/single_item.dart';
import 'package:meal/model/product.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/tools.dart';

class ProductInfo extends StatefulWidget {
  const ProductInfo({Key? key}) : super(key: key);

  @override
  State<ProductInfo> createState() => _ProductInfoState();
}

class _ProductInfoState extends State<ProductInfo> {
  late ProductModel product;

  @override
  void initState() {
    super.initState();
    product = Get.arguments as ProductModel;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('商品详情',
          actions: ToolsUtils.actions('编辑', pressed: () {
            Get.toNamed(RouteGet.productEdit, arguments: product);
          })),
      body: SingleChildScrollView(
        child: product.meal ? SetMeal(product: product) : SingleItem(product: product),
      ),
    );
  }
}
